import request from '@/utils/request'

// 网站管理
export function getWebsites(params) {
  return request({
    url: '/static_web/api/website/',
    method: 'get',
    params
  })
}

export function getWebsite(id) {
  return request({
    url: `/static_web/api/website/${id}/`,
    method: 'get'
  })
}

export function createWebsite(data) {
  return request({
    url: '/static_web/api/website/',
    method: 'post',
    data
  })
}

export function updateWebsite(id, data) {
  return request({
    url: `/static_web/api/website/${id}/`,
    method: 'put',
    data
  })
}

export function deleteWebsite(id) {
  return request({
    url: `/static_web/api/website/${id}/`,
    method: 'delete'
  })
}

// 部署管理
export function deployWebsite(websiteId) {
  return request({
    url: `/static_web/api/deploy/${websiteId}/`,
    method: 'post'
  })
}

export function undeployWebsite(websiteId) {
  return request({
    url: `/static_web/api/deploy/${websiteId}/undeploy/`,
    method: 'post'
  })
}

export function getDeployInfo(websiteId) {
  return request({
    url: `/static_web/api/deploy/${websiteId}/info/`,
    method: 'get'
  })
}

// 页面管理
export function getPages(params) {
  return request({
    url: '/static_web/api/page/',
    method: 'get',
    params
  })
}

export function getPage(id) {
  return request({
    url: `/static_web/api/page/${id}/`,
    method: 'get'
  })
}

export function createPage(data) {
  return request({
    url: '/static_web/api/page/',
    method: 'post',
    data
  })
}

export function updatePage(id, data) {
  return request({
    url: `/static_web/api/page/${id}/`,
    method: 'put',
    data
  })
}

export function deletePage(id) {
  return request({
    url: `/static_web/api/page/${id}/`,
    method: 'delete'
  })
}

export function previewPage(id) {
  return request({
    url: `/static_web/api/page/${id}/preview/`,
    method: 'get'
  })
}

export function publishPage(id) {
  return request({
    url: `/static_web/api/page/${id}/publish/`,
    method: 'post'
  })
}

// 构建管理
export function triggerBuild(websiteId) {
  return request({
    url: `/static_web/api/build/${websiteId}/trigger/`,
    method: 'post'
  })
}

export function getBuildStatus(websiteId) {
  return request({
    url: `/static_web/api/build/${websiteId}/status/`,
    method: 'get'
  })
}

export function getBuildHistory(websiteId) {
  return request({
    url: `/static_web/api/build/${websiteId}/history/`,
    method: 'get'
  })
}

// AI操作
export function aiGeneratePage(data) {
  return request({
    url: '/static_web/api/ai/generate_page/',
    method: 'post',
    data
  })
}

export function aiModifyPage(data) {
  return request({
    url: '/static_web/api/ai/modify_page/',
    method: 'post',
    data
  })
}

export function aiOptimizePage(data) {
  return request({
    url: '/static_web/api/ai/optimize_page/',
    method: 'post',
    data
  })
}

export function aiBatchCreate(data) {
  return request({
    url: '/static_web/api/ai/batch_create/',
    method: 'post',
    data
  })
}

export function aiExtractFromImage(data) {
  return request({
    url: '/static_web/api/ai/extract_from_image/',
    method: 'post',
    data
  })
}

// AI创建网站
export function aiAnalyzeRequirements(data) {
  return request({
    url: '/static_web/api/ai/analyze_requirements/',
    method: 'post',
    data
  })
}

export function aiCreateCompleteWebsite(data) {
  return request({
    url: '/static_web/api/ai/create_complete_website/',
    method: 'post',
    data
  })
}

// 页面配置文件管理
export function generatePageConfig(pageId) {
  return request({
    url: `/static_web/api/page/${pageId}/generate_config/`,
    method: 'post'
  })
}

export function downloadPageConfig(pageId) {
  return request({
    url: `/static_web/api/page/${pageId}/download_config/`,
    method: 'get',
    responseType: 'blob'
  })
}

export function regenerateFromConfig(pageId) {
  return request({
    url: `/static_web/api/page/${pageId}/regenerate/`,
    method: 'post'
  })
}

export function generateAllConfigs(websiteId) {
  return request({
    url: `/static_web/api/website/${websiteId}/generate_all_configs/`,
    method: 'post'
  })
}

// AI交互式生成Prompt
export function generatePromptInteractive(data) {
  return request({
    url: '/static_web/api/prompt/generate_interactive/',
    method: 'post',
    data,
    responseType: 'stream' // 流式响应
  })
}

export function saveGeneratedPrompt(data) {
  return request({
    url: '/static_web/api/prompt/save/',
    method: 'post',
    data
  })
}
